#:import LinearRecycleLayoutManager kivy.garden.recycleview.LinearRecycleLayoutManager

#     Goblinoid: Experience all of MediaGoblin on an Android Device
#     Copyright (C) 2015 Dylan Jeffers 
# 
#     This program is free software: you can redistribute it and/or modify
#     it under the terms of the GNU General Public License as published by
#     the Free Software Foundation, either version 3 of the License, or
#     (at your option) any later version.
# 
#     This program is distributed in the hope that it will be useful,
#     but WITHOUT ANY WARRANTY; without even the implied warranty of
#     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#     GNU General Public License for more details.
# 
#     You should have received a copy of the GNU General Public License
#     along with this program.  If not, see <http://www.gnu.org/licenses/>.
    
# box layout for each activity in feed
# Note: classes will have simpler implementation as different sections
# are abstracted
<FeedLayout>
    id: feed_layout
    padding: 20
    orientation: 'vertical'
    BoxLayout:
        size_hint: (1.0, 0.05)
        orientation: 'horizontal'
        Button:
            halign: 'left'
            text: root.actor 
            on_release: root.open_profile_modal()
        Label:
            halign: 'right' 
            text: '{0} hrs, {1} min'.format(root.post_time[0], root.post_time[1])
    RelativeLayout:
        orientation: 'horizontal'
        # size_hint_y: None
        # Note: change this to wrap activity text
        size_hint: (1.0, 0.6)
        id: content
        AsyncImage:
            size_hint_x: None
            source: root.image_content
            allow_stretch: True
            keep_ratio: True 
            width: content.width
            opacity: 1 if root.image_content else 0
        Button:
            size_hint_x: None
            width: content.width
            text: root.else_content
            opacity: 1 if root.else_content else 0
    BoxLayout:
        size_hint: (1.0, 0.05)
        orientation: 'horizontal'
        Button:
            text: 'comment'
            on_release: root.open_comment_modal()

    BoxLayout:
        size_hint_y: 0.3
        orientation: 'vertical'
        Label:
            size_hint_y: 0.5
            text: root.description
            text_size: root.width, self.height
            valign: 'middle'
        BoxLayout:
            orientation: 'horizontal'
            # Note: this will eventually not be hard-coded
            FeedViewComments:
                index: root.index
                comments: root.comments

<FeedView>:
    BoxLayout:
        orientation: 'vertical'
        RecycleView:
            size_hint_y: 1 
            opacity: 1 if root.data else 0
            layout_manager: LinearRecycleLayoutManager(orientation="vertical",default_size=self.height)
            data: root.data
            viewclass: 'FeedLayout'

<FeedViewComments>
    orientation: 'vertical'
    Button:
        text: 'view all {0} comments'.format(len(root.comments))
        on_release: root.open_comment_modal()
    
<CommentSnapshot>
    max_lines: 1
    padding_y: 5.0
    text_size: root.size

#root view for gallery, photo, video, and upload subviews 
<MediaView>
    msm: msm 
    #Note: No BoxLayout allows MediaView to take up full screen
    BoxLayout:
        orientation: 'vertical'
        ScreenManager:
            size_hint: (1.0, 0.9)
            id: msm
        BoxLayout:
            size_hint: (1.0, 0.1)
            Button:
                text: 'gallery'
                on_release: root.open_media_view('gallery', True)
            Button:
                text: 'camera'
                on_release: root.open_media_view('camera', False)
            Button:
                text: 'video'
                on_release: root.open_media_view('camcorder', False)


<ProfileModalView>
    BoxLayout:
        orientation: 'vertical'
        BoxLayout:
            size_hint_y: 0.1
            orientation: 'horizontal'
            Button:
                size_hint_x: 0.2
                text: 'exit'
                on_release: root.dismiss()
            Label:
                text: str(root.profile.display_name) if root.profile else ''
            Button:
                size_hint_x: 0.2
                text: 'Log Out'
                on_release: root.log_out()  
        TabbedProfilePanel:
            profile: root.profile
    

<TabbedProfilePanel>:
    activity_grid: activity_grid
    follower_grid: follower_grid
    following_grid: following_grid
    do_default_tab: False
    tab_pos: 'top_mid'
    TabbedPanelItem:
        text: 'activity'
        BoxLayout:
            orientation: 'vertical'
            ScrollView:
                size: self.size  
                GridLayout:
                    id: activity_grid
                    cols: 1
                    size_hint_y: None
                    row_default_height: 200 
    TabbedPanelItem:
        text: 'followers'
        BoxLayout:
            orientation: 'vertical'
            ScrollView:
                size: self.size  
                GridLayout:
                    id: follower_grid
                    cols: 1
                    size_hint_y: None
                    row_default_height: 200 
    TabbedPanelItem:
        text: 'following'
        BoxLayout:
            orientation: 'vertical'
            ScrollView:
                size: self.size  
                GridLayout:
                    id: following_grid
                    cols: 1
                    size_hint_y: None
                    row_default_height: 200 

        

<SettingsView>
    BoxLayout:
        orientation:'vertical'

        ActionBar:
            pos_hint: {'top':1}
            ActionView:
                use_separator: True
                ActionPrevious:
                    title: 'MediaGoblin'
                    with_previous: False
                ActionOverflow:
                ActionButton:
                    on_release: app.open_feed(self)
                    text: 'Feed'
        Label:
            text: 'User Name'


<CommentModalView>:
    comment_layout: comment_layout
    BoxLayout:
        orientation: 'vertical'
        auto_dismiss: False
        AnchorLayout:
            size_hint_y: 0.05
            anchor_y: 'top'
            Button:
                text: 'exit'
                on_release: root.dismiss()
                
        ScrollView:
            size_hint_y: 0.9
            size: self.size
            GridLayout:
                id: comment_layout
                cols: 1
                size_hint_y: None
                row_default_height: 300
        AnchorLayout:
            size_hint_y: 0.05
            anchor_y: 'bottom'
            BoxLayout:
                orientation: 'horizontal'
                TextInput:
                    id: comment_input
                    hint_text: 'comment'
                    height: self.minimum_height
                Button:
                    size_hint_x: 0.1
                    text: 'post'
                    on_release: root.post_comment(comment_input.text)



<ActivityDescriptionCell>:
    orientation: 'horizontal'
    padding: [0,10,0,30]
    Label:
        size_hint_x: None
        text: str(root.actor) if root.actor else ''
        text_size: self.size
    Label:
        size_hint_y: None
        text_size: self.width, None
        height: self.texture_size[1]
        text: str(root.description) if root.description else ''

<CommentModalViewCell>
    orientation: 'horizontal'
    padding: [0,10,0,10]
    Button:
        size_hint_x: None
        text: str(root.comment.author) if root.comment else 'no author'
        text_size: self.size
        valign: 'middle'
        on_release: root.open_profile_modal()
    ScrollView:
        size: self.size  
        Label:
            size_hint_y: None
            text_size: self.width, None
            height: self.texture_size[1]
            text: root.comment.content if root.comment else 'no comment'
         

# the following activity content types may be moved to a different kv
# file in the future

<ANote>:
    text_size: self.width, None
    valign: 'middle'
    halign: 'center'
    height: self.texture_size[1]


<AImage>:
